package com.devbobcorn.nekoration.network;

import java.util.function.Supplier;

import com.devbobcorn.nekoration.client.ClientHelper;

import net.minecraft.network.PacketBuffer;
import net.minecraft.util.text.ITextComponent;
import net.minecraftforge.fml.network.NetworkEvent;

public class S2CChangeMusic {
    public String name;

	public S2CChangeMusic(String name) {
        this.name = name;
    }

	public static void encode(final S2CChangeMusic msg, final PacketBuffer packetBuffer) {
		System.out.println(msg.name);
		ITextComponent c = ITextComponent.nullToEmpty(msg.name);
		System.out.println(c.getContents());
        packetBuffer.writeComponent(c);
    }

	public static S2CChangeMusic decode(final PacketBuffer packetBuffer) {
		return new S2CChangeMusic(packetBuffer.readComponent().getContents());
	}

	public static void handle(final S2CChangeMusic msg, final Supplier<NetworkEvent.Context> contextSupplier) {
        contextSupplier.get().enqueueWork(() -> {
			//Handle this on CLIENT SIDE...
			ClientHelper.switchTrack(msg.name);
        });
        contextSupplier.get().setPacketHandled(true);
	}
}